<!DOCTYPE HTML>
<html>
<head>
    <title>Todo</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/editor/common.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body  style="padding: 0;width: 100%;height: 100%">
<div  style="width:100%;height:97%;">
    <div showCollapseButton="true" style="height: 100%">
        <div id="outImg">
            <img id="imgId" src="" alt="" onclick="smallImg()">
        </div>
        <div style="padding: 5px">
            <span>部落名称：</span>
            <input id="btnEdit1" class="mini-buttonedit" onbuttonclick="onButtonEdit" name="a" textName="b"/>
            <span>直播流id：</span><input  class="mini-textbox" type="text" id="qiniuStreamId"/>
            <span>直播人id：</span><input  class="mini-textbox" type="text" id="createrOId"/>
            <span>直播人昵称：</span><input  class="mini-textbox" type="text" id="nickName"/>
            <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
        </div>
        <div style="width:99%;">
            <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
                <table style="width:100%;">
                    <tr>
                        <td style="width:100%;">
                            <a class="mini-button" iconCls="icon-add" onclick="liveAdd()">增加</a>
                            <a class="mini-button" iconCls="icon-add" onclick="deviceLiveAdd()">设备直播</a>
                            <a class="mini-button" iconCls="icon-edit" onclick="getDeviceLiveUrlForIp()">获取推流地址</a>
                            <a class="mini-button" iconCls="icon-add" onclick="goodsAdd()">增加商品</a>
                            <!--<a class="mini-button" iconCls="icon-add" onclick="allGoods()">全部商品</a>-->
                            <a class="mini-button" iconCls="icon-edit" onclick="liveEdit()">编辑</a>
                            <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>
                            <a class="mini-button" onclick="copy()">复制</a>
                            <a class="mini-button" onclick="guanlianQuestion()">调查问卷</a>
                            <a class="mini-button" onclick="clearQuestion()">清除问卷</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="datagrid1" class="mini-datagrid" style="width:99%;height: 82%;"
             url="/getdata/liveManger" idField="id" allowResize="true"
             sizeList="[20,30,50,100]" pageSize="30"
        >
            <div property="columns">
                <div type="checkcolumn" ></div>
                <div field="qiniuStreamId" width="100" align="center" align="left" headerAlign="center">直播流ID</div>
                <div field="nickName" width="60"  align="center"  headerAlign="center">主播名</div>
                <div field="isRecord" width="40"  renderer="isRecordRenderer" align="center" headerAlign="center">直播类型</div>
                <div field="title" width="100"  align="left" headerAlign="center">直播标题</div>
                <div field="tribeName" width="100" align="left" headerAlign="center">部落名</div>
                <div field="createrOId" width="100"  align="left" headerAlign="center">直播人Id</div>
                <div field="playTime" width="100" align="center" renderer="playTimeRenderer" align="center" headerAlign="center">直播时长(分钟)</div>
                <div field="status" width="100" align="center" renderer="statusRenderer" align="center" headerAlign="center">状态</div>
                <div field="userAvatar"  width="30" align="center" headerAlign="center"  >直播头像</div>
                <div field="rtmpUrl"  width="30" align="center" headerAlign="center"  >推流地址</div>
                <div field="firstLevel"  width="50" align="center" headerAlign="center" >第一价格</div>
                <div field="lastLevel"  width="50" align="center" headerAlign="center" >最后价格</div>
                <div field="browseNum"  width="50" align="center" headerAlign="center" >观看直播人数</div>
                <div field="streambackup"  width="50" align="center" headerAlign="center"  >播放</div>
                <div field="questionTitle"  width="50" align="center" headerAlign="center"  >调查问卷</div>
                <div field="objectId"  width="50" renderer="liveRenderer" align="center" headerAlign="center"  >直播地址</div>
                <div field="startTime" width="70"   align="center" headerAlign="center">开播时间</div>
                <div field="endTime" width="70"   align="center" headerAlign="center">结束时间</div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    var flag = 1;
    mini.parse();
    var grid = mini.get("datagrid1");
    grid.load();
    grid.on("drawcell", function (e) {
        var  value = e.value;
        column = e.column;
        //将性别文本替换成图片
        if (column.field == "userAvatar") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
        if (column.field == "streambackup") {
            e.cellHtml = '<a onclick="startLive()">播放</a>';
        }
        if (column.field == "objectId") {
            e.cellHtml = '<a onclick="showLive()">直播地址</a>';
        }
    });
    function startLive() {
        var row = grid.getSelected();
        var objectId = row.objectId;
        mini.open({
            url: "/getdata/liveBack?streambackup="+row.streambackup+"&objectId="+row.objectId+"&status="+row.status+"&isRecord="+row.isRecord,
            title: "直播", width: 640, height: 450,

            ondestroy: function (action) {

                grid.reload();

            }
        });
    }
    function showLive() {
        var row = grid.getSelected();
        window.open("http://health.aladada.com/shareLive?type="+0+"&liveId="+row.objectId+"&uId="+row.createrOId+"&tId="+row.tribeOId+"&code="+'071twVcU1KnCuU0N2z9U1uo3dU1twVc9')
    }
    function search() {
        var tribeOId = mini.get("btnEdit1").getValue();
        var qiniuStreamId = mini.get("qiniuStreamId").getValue();
        var createrOId = mini.get("createrOId").getValue();
        var nickName = mini.get("nickName").getValue();
        grid.load({
            tribeOId: tribeOId,
            qiniuStreamId:qiniuStreamId,
            createrOId:createrOId,
            nickName:nickName,
        });
        var btnEdit1 = mini.get("btnEdit1");
        btnEdit1.setText("");
        btnEdit1.setValue("");
    }
    $("#btnEdit1,#qiniuStreamId,#createrOId,#nickName").bind("keydown", function (e) {
        if (e.keyCode == 13) {
            search();
            var btnEdit1 = mini.get("btnEdit1");
            btnEdit1.setText("");
            btnEdit1.setValue("");
        }
    });


    function remove() {
        var row = grid.getSelected();
        if (row) {
            $.ajax({
                url:"/getdata/removeLive",
                type:'POST',
                data:{
                    objectId:row.objectId,
                    status:-1
                },
                success:function (result) {
                  if (result == '1'){
                    alert('直播删除成功！')
                  } else {
                    alert('直播删除失败！')
                  }
                  grid.reload();
                }
            });
        } else {
            alert("请选中一条记录");
        }
    }
    function guanlianQuestion() {
        var row = grid.getSelected();
        if (row){
            mini.open({
                url: "/getdata/liveGuanlianQuestion?objectId="+row.objectId,
                title: "编辑", width: 800, height: 600,

                ondestroy: function (action) {

                    grid.reload();

                }
            });
        }else{
            alert("请选中一条记录")
        }
    }
    function clearQuestion() {
        var row = grid.getSelected();
        if (row){
            var objectId = row.objectId;

            $.ajax({
                type: "post",
                url: "/getdata/guanlianQuestionLive",
                cache: false,

                data: {
                    objectId:'',
                    liveId:objectId,
                },
                success: function (result) {
                    grid.reload();
                },
                error: function (error) {
                    console.log(error)
                }
            })        }else{
            alert("请选中一条记录")
        }
    }

    function liveEdit() {
        var row = grid.getSelected();
        if (row){
            mini.open({
                url: "/getdata/liveEdit?objectId="+row.objectId,
                title: "编辑", width: 400, height: 250,

                ondestroy: function (action) {

                    grid.reload();

                }
            });
        }else{
            alert("请选中一条记录")
        }
    }

    function copy() {
        let row = grid.getSelected();
        console.log(row.objectId,"-------==============")
        if(row){
            mini.open({
                url:"/getdata/liveCopy?objectId="+row.objectId,
                onload:function () {
                }
            })
        }
    }
    function liveAdd() {
        mini.open({
            url: "/getdata/liveAdd/",
            title: "编辑", width: 650, height: 400,

            ondestroy: function (action) {

                grid.reload();

            }
        });

    }
    function deviceLiveAdd() {
      mini.open({
        url: "/getdata/deviceLiveAdd/",
        title: "编辑", width: 650, height: 400,

        ondestroy: function (action) {

          grid.reload();

        }
      });
    }
    function getDeviceLiveUrlForIp() {
      var row = grid.getSelected();
      if (row) {
        if (row.rtmpUrl){
          mini.open({
            url: "/editor/rtmpUrlToIPShowView?rtmpUrl="+row.rtmpUrl,
            title: "获取推流地址", width: 650, height: 400,

            ondestroy: function (action) {

//              grid.reload();

            }
          });
        } else {
          alert("没有推流地址，无法获取IP地址！");
        }
      } else {
        alert("请选中一条记录");
      }
    }
    function goodsAdd() {
        var row = grid.getSelected();
        if (row){
            console.log(row)
            mini.open({
                url: "/getdata/live/goods?tribeOId="+row.tribeOId+"&objectId="+row.objectId,
                title: "编辑", width: 650, height: 800,

                ondestroy: function (action) {

                    grid.reload();

                }
            });
        }else{
            alert("请选中一条记录")
        }
    }

    function bigImg() {
        var row = grid.getSelected();
        if (row) {
            if(flag==1) {
                var path = row.userAvatar;
                $("#imgId").attr('src', path);
                $("#outImg").css('display','block');
            }
        }
    }
    function smallImg() {
        $("#outImg").css('display','none');
    }

    function statusRenderer(e) {
        var value = e.value;
        if (value==-1) {
            return (value, '删除')
        }else if(value==0){
            return (value, '禁播')
        }else if(value==1){
            return (value,'预约')
        }else if(value==2){
            return (value,'直播中')
        }else if(value==3){
            return (value,'结束')
        }else if(value==4){
            return (value,'录播')
        }
    }
    function playTimeRenderer(e) {
        var value = e.value;
        if (typeof(value)=="number") {
            return (value, value+'分钟')
        }else {
          return (value, '录播')
        }
    }
    function isRecordRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value, '录播')
        }else if(value==0){
            return (value, '直播')
        }else if(value==2){
            return (value, '上传视频')
        }else if(value==3){
          return (value, '定时直播')
        }else if(value==4){
          return (value, '设备直播')
        }
    }


    function onButtonEdit(e) {
        var btnEdit = this;
        mini.open({
            url: "/editor/tribeChoice",
            title: "选择列表",
            width: 700,
            height: 450,
            ondestroy: function (action) {
                if (action == "ok") {
                    var iframe = this.getIFrameEl();
                    var data = iframe.contentWindow.GetData();
                    data = mini.clone(data);    //必须
                    if (data) {
                        btnEdit.setValue(data.id);
                        btnEdit.setText(data.text);
                        grid.load({
                            tribeOId:data.id,
                        });
                    }
                }else {
                    btnEdit.setText("");
                    btnEdit.setValue("");
                    grid.load();
                }

            }
        });

    }
</script>
</html>